<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ include file="/jsplib/pubhead.jsp"%>
<%@ page import="net.comm.common.ValueMaping" %>
<%@ taglib uri="/WEB-INF/myTaglib.tld" prefix="tag"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>上传照片</title>
	<link href="${cpath}/css/youlin.css" rel="stylesheet" type="text/css" media="all" />
	<script type="text/javascript" src="${cpath}/js/global.js"></script>

</head>
<body>
<script> 
	var more_pic = 5;
	if(more_pic < 0){more_pic = 0;}
</script>
<!--外套 start -->
<div class="wrap">
  <!--页首 start -->
	<%@ include file="/menu.jsp"%>
  <!--页首 end -->  
  
  <!--导航面包屑 start -->
  <div class="breadCrumb">
  <div class="breadCrumbNav">当前位置：<a href="${cpath}/users.do?action=main">我的主页</a> 
	<c:if test="${theForm.qryGroupID != 99999999}">	
    >> <a href="${cpath}/group_get/groupID_${theForm.qryGroupID}.html">部落</a>
	</c:if>
	</div>
	<%@ include file="/navf.jsp"%> 
 </div> 
  <!--导航面包屑 end -->
  
  <!--主体 start -->
 <div class="body">
 
  <div class="hotBox1">  
    <div class="hotBox1-left">		
		<c:if test="${theForm.qryGroupID != 99999999}">	
		<a href="${cpath}/group_get/groupID_${theForm.qryGroupID}.html"><img src="${cpath}/${myfn:getGroupPic(theForm.qryGroupID)}"  width="75" height="75" class="shequ icon user_icon_2"></a>
        <p><b><a href="${cpath}/group_get/groupID_${theForm.qryGroupID}.html">${myfn:getGroupName(theForm.qryGroupID)}</a> </b></p>
        <p>上传照片</p>
		</c:if>
		<c:if test="${theForm.qryGroupID == 99999999}">
		<a href="${cpath}/users.do?action=home&userID=${theForm.userID}"><img src="${cpath}/${myfn:getUserPic(theForm.userID)}"  width="75" height="75" class="shequ icon user_icon_2"></a>
        <p><b><a href="${cpath}/users.do?action=home&userID=${theForm.userID}">${myfn:getUserName(theForm.userID)}</a> </b></p>
        <p>上传照片</p>
		</c:if>
    </div>
    <div class="hotBox1-right">
      <p><a href="javascript:history.go(-1);"><img src="${cpath}/images/icon_32.gif" width="137" height="25" /></a></p>
      <p>&nbsp;</p>    
    </div>
  </div> 
  
 <div class="left-Box6">
	<h3 class="nav"><a >上传照片</a></h3>

  <div class="left-Box6-content">
   <div class="left-Box6-content-inner">   
	<form  name="frm_upload" action="${cpath}/gpic.do?action=add"  method="post"  enctype="multipart/form-data" class="frmAddTopic">
		<p><label>相册：</label>
			<select name="galbumID" >
				<c:forEach var="album" items="${albumlist}" varStatus="status">   
				<option value="${album.galbumID}" 
				<c:if test="${theForm.galbumID == album.galbumID}"> SELECTED</c:if> 
				>${album.albumname}
				</c:forEach> 		
			</select>
		</p>
		<p><label>上传照片：</label>
							<INPUT id=max_file_size type=hidden value=3096152 name=MAX_FILE_SIZE>
							<IMG id=oFileChecker style="WIDTH: 0px; HEIGHT: 0px" onload=check_photo_size()> 
							<TABLE id=file_table class="file_table">
								<SCRIPT type=text/javascript>
									function add_file_item()
									{
										var oTable = document.getElementById("file_table");
										if (oTable.rows.length >= more_pic) {
											if (more_pic == 0) {
												alert("每人最多可以上传"+more_pic+"张，您已经上传了"+more_pic+"张照片");
											} else {
												alert("一次最多可以上传"+more_pic+"张照片");
											}
											return;
										 }
										 var oTr = oTable.insertRow(oTable.rows.length);
										 var oTd = oTr.insertCell(0);
										 var htmlStr = '照片：<input type="file" class="in" name="upFile[]"  onchange="check_fileszie(this);" />';
										 htmlStr += '&emsp;<input type="button" value="取消" onclick="del_file_item(event)" />&emsp;';
										 htmlStr += '<em onclick="add_file_item()" style="cursor:pointer; font-style:normal; border-bottom:1px solid #014391; color:#014391;">上传更多</em><SPAN style="display:block;">描述：<INPUT maxlength="255" class="in" type="text" name=descr[]></SPAN>';
										 oTd.innerHTML = htmlStr; 
										 hidden_upside_file_more();
									 }
									 function hidden_upside_file_more()
									 {
										 var oTable = document.getElementById("file_table");
										 var oldIndex = oTable.rows.length-2 > 0 ? oTable.rows.length-2 : 0;
										 var oAOld = oTable.rows[oldIndex].firstChild.lastChild.previousSibling;
										 oAOld.style.display = "none";
									 }
									 function show_upside_file_more()
									 {
										 var oTable = document.getElementById("file_table");
										 var oldIndex = oTable.rows.length-1 > 0 ? oTable.rows.length-1 : 0;
										 var oAOld = oTable.rows[oldIndex].firstChild.lastChild.previousSibling;
										 oAOld.style.display = "";
										}
										function del_file_item(e)
										{
											 if (window.event) {
													 e = window.event;
													 e_src = e.srcElement;   
											 } else {
													 e_src = e.target;
											 }
											 document.getElementById('file_table').deleteRow(e_src.parentNode.parentNode.rowIndex);   
											 show_upside_file_more();
										}
								</SCRIPT>
								<TBODY>
								<TR>
									<TD >
									照片：<INPUT type=file class="in" onchange="javascript:check_fileszie(this);" name=upFile[]>
									<EM style="CURSOR: pointer; COLOR: #014391; BORDER-BOTTOM: #014391 1px solid; FONT-STYLE: normal" onclick=add_file_item()>上传更多</EM>
									<SPAN style="display:block;">描述：<INPUT maxlength="255" class="in" type="text" name=descr[]></SPAN></TD></TR>
									
								</TBODY></TABLE>&nbsp;&nbsp;
								<INPUT id=submit_photo type=image src="${cpath}/images/btn04_usercpphoto.jpg" onclick="upload_photo();">
	    </p>
		<p><label></label>
			<FONT color=red>严禁上传色情、暴力、恐怖、反动等违法照片，如果您的照片被会员投诉为上述照片，经查实会将您列入网站黑名单，以后都将无法注册和登录网站！</FONT><BR>*支持格式：jpg、jpeg、gif。<BR>* 上传照片，每张大小不要超过3M。<BR>* 同时最多可以上传&nbsp;<STRONG>5</STRONG>&nbsp;张照片。
			<!--隐藏域-->
			<input type="hidden" name='isHead'		value='2'/>
			<input type="hidden" name='userID'		value='${userID}'/>
			<input type="hidden" name='qryGroupID'	value='${theForm.qryGroupID}'/>
		</p>
     </form>
      </div>
   <div class="clearFloat"></div>
  </div>
</div>
  
    <div class="clearFloat"></div>
 </div> 
 <!--主体 end -->
 
 
 <!--页脚 start -->
	<%@ include file="/foot.jsp"%>
 <!--页脚 end --> 
</div>
<!--外套 end -->

</body>
</html>
<!---->
<SCRIPT type=text/javascript>

	function my_getbyid(id)
	{

		 itm = null;
		 if (document.getElementById)
		 {
			itm = document.getElementById(id);
		 }
		 else if (document.all)
		 {
			itm = document.all[id];
		 }
		 else if (document.layers)
		 {
			itm = document.layers[id];
		 }
		 
		 return itm;
	}

	function check_photo_size()
	{
		img_temp = my_getbyid('oFileChecker');
		var limit = parseInt(my_getbyid('max_file_size').value);
		if (img_temp.fileSize > limit) {
			alert("照片文件过大，请选择2M以下的文件上传");
			return false;
		}
	}
	function check_fileszie(filePicker)
	{
		var patn = /.jpg$|.jpeg$|.gif$/i;  
		if(patn.test(filePicker.value)) {
			img_temp = my_getbyid('oFileChecker');
			img_temp.src = filePicker.value;
		} else {
			alert('您选择的不是合法的图片文件,支持文件格式：.jpg/.jpeg/.gif，请重新选择');
			filePicker.value='';
			return false;
		}
		return true;
	}	

	function chk_upload_photo()
	{

		if(more_pic == 0) { 
			alert("照片数量已达规定张数，请至少删除1张之后再上传");
			return false;
		}
		var nopic = 0;
		var oP, haveP=0;
		var patn = /.jpg$|.jpeg$|.gif$/i;  
		var files = document.getElementsByName('upFile[]');
		var descrs = document.getElementsByName('descr[]');
		for (var i=0,j=0; i < files.length; i++) {
			if (files[i].value.length > 1) {
				haveP = 1;
				//*if(descrs[i].value.replace(/(^\s*)|(\s*$)/g,"") == "") {
				//*	j = i+1;
				//*	alert('第'+j+'个图片文件没有填写描述');
				//*	return false;
				//*}
				if(!patn.test(files[i].value)) {
					j = i+1;
					alert('第'+j+'个不是合法的图片文件,支持文件格式：.jpg/.jpeg/.gif，请重新选择');
					return false;
				}
				nopic = i; 
				files[i].name = "upFile"+ nopic;
				descrs[i].name = "descr" + nopic;
			}
		}
		if (haveP == 0) {
			alert("请选择要上传的照片");
			return false;
		}
	}

	function upload_photo()
	{
		var form = document.frm_upload;

		my_getbyid('submit_photo').src ='${cpath}/images/upload.gif'
		my_getbyid('submit_photo').onclick = "";

		if(chk_upload_photo()){
//			form.submit();		
		}
	}

</script>
